package com.znsd.zl.house.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.znsd.zl.house.dao.HouseImageDao;
import com.znsd.zl.house.entity.HouseImageEntity;
import com.znsd.zl.house.service.HouseImageService;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


/**
 * @ClassName THouseImage
 * @Description 描述
 * @author jaypdd
 * @email jaypdd@163.com
 * @date 2020-08-26 23:20:43
 * @Version v1.0
 */
@Service("houseImageService")
public class HouseImageServiceImpl extends ServiceImpl<HouseImageDao, HouseImageEntity> implements HouseImageService {


	@Override
	public List<HouseImageEntity> firstFive() {
		return baseMapper.firstFive();
	}


	@Override
	public String setSlideshow(Integer id){

		HouseImageEntity byId = baseMapper.selectById(id);
		if (byId.getSlideshow()==0){
			baseMapper.joinSlideshow(id);
			return "已加入轮播图";
		}else{
			baseMapper.reSlideshow(id);
			return "已撤销轮播图";
		}

	}

	@Override
	public boolean save(HouseImageEntity t){
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String format = df.format(new Date());
		t.setCreateDate(format);
		t.setUpdateDate(format);
		baseMapper.insert(t);
		return  true;
	}

	@Override
	public List<HouseImageEntity> findByHouseImage(Integer houseId) {
		List<HouseImageEntity> images = baseMapper.findByHouseImage(houseId);
		return images;
	}

	@Override
	public boolean updateById(HouseImageEntity entity) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String format = df.format(new Date());
		entity.setUpdateDate(format);
		baseMapper.updateById(entity);
		return true;
	}
}
